//
//  NSObject+Property.m
//  05-Runtime(自动生成模型的属性代码)
//
//  Created by albert on 16/5/10.
//  Copyright © 2016年 albert. All rights reserved.
//

#import "NSObject+Property.h"

@implementation NSObject (Property)
+ (void)createPropertyCodeWithDict:(NSDictionary *)dict{
    
    NSMutableString *tmpStr = [NSMutableString string];

    // 遍历字典
    [dict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull propertyKey, id  _Nonnull value, BOOL * _Nonnull stop) {
        //NSLog(@"%@ %@", propertyKey, [value class]);
        
        NSString *code;
        
        if ([value isKindOfClass:NSClassFromString(@"__NSCFString")]) {
            code = [NSString stringWithFormat:@"/** <#注释#> */\n@property (nonatomic, copy) NSString *%@;",propertyKey]
            ;
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFNumber")]){
            code = [NSString stringWithFormat:@"/** <#注释#> */\n@property (nonatomic, assign) int %@;",propertyKey]
            ;
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFArray")]){
            code = [NSString stringWithFormat:@"/** <#注释#> */\n@property (nonatomic, strong) NSArray *%@;",propertyKey]
            ;
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFDictionary")]){
            code = [NSString stringWithFormat:@"/** <#注释#> */\n@property (nonatomic, strong) NSDictionary *%@;",propertyKey]
            ;
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){
            code = [NSString stringWithFormat:@"/** <#注释#> */\n@property (nonatomic, assign) BOOL %@;",propertyKey]
            ;
        }// 有其它的还可以再补充
        [tmpStr appendFormat:@"\n%@\n",code];
    }];
    
    NSLog(@"%@", tmpStr);
}
@end
